package com.company.regist.servlet;

import com.company.regist.dao.IRegisterDAO;
import com.company.regist.dao.RegisterDAOImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username=req.getParameter("username");

        String password = req.getParameter("password");
        IRegisterDAO dao = new RegisterDAOImpl();
        int p=-1;
        try {
            p = dao.updateByUserName(username,password);
            if(p>=1)
            {

                resp.setHeader("Content-Type","text/html;charset=utf-8");
                resp.getWriter().print("修改成功，即将为您跳转主页......");
                resp.setHeader("refresh","2,url=dirct.html");
            }
            else
            {
                resp.getWriter().print("update fail");
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
